<template>
  <!-- 退出机构 -->
  <el-dialog top="20vh" :title="$t('add.add189')" :visible.sync="dialogShow" width="700px" :close-on-click-modal="false">
    <div class="join">
      <div style="margin-bottom: 30px" class="tip">
        <span v-if="1 == 2">您是最后一个机构管理员，请移交管理员权限后再重试。</span>
        <span>{{ $t('add.add190') }}【{{ form.name }}】{{ $t('add.add191') }}</span>
      </div>
      <div style="margin-bottom: 60px">
        <el-form
          ref="form"
          label-position="top"
          label-width="200px"
          :model="form"
          :rules="rules"
          :size="formItemSize"
        >
          <el-form-item :label="$t('add.add105') + '：'" prop="remark">
            <el-input
              v-model="form.remark"
              :autosize="{ minRows: 5 }"
              type="textarea"
              :placeholder="$t('add.add192')"
              maxlength="200"
              show-word-limit
            />
          </el-form-item>
        </el-form>
      </div>
    </div>

    <div slot="footer" class="dialog-footer">
      <el-button plain :size="optionButtonSize" @click="cancleHandle">{{
        $t('add.add203')
      }}</el-button>
      <el-button type="primary" :size="optionButtonSize" @click="submitHandle">{{
        $t('members.chengyuan31')
      }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'BLZMasterIndex',

  data() {
    return {
      form: {
        deptId: null,
        name: '',
        remark: '',
      },
      rules: {
        remark: [{ required: true, message: this.$t('add.add079'), trigger: 'blur' }],
      },
      dialogShow: false,
    };
  },

  mounted() {},

  methods: {
    cancleHandle() {
      this.dialogShow = false;
    },
    submitHandle() {
      if (!this.form.remark) {
        return this.$message.error(this.$t('add.add192'));
      }
      this.$http
        .post('/sys/organized/exitOrganized', this.form)
        .then(({ data: res }) => {
          console.log('res--->', res);
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.$http
              .get('/sys/organized/getOptionLabel')
              .then(({ data: res }) => {
                if (res.code !== 0) {
                  return this.$message.error(res.msg);
                } else {
                  let data = res.data;
                  if (data.length > 0) {
                    window.location.reload();
                  } else {
                    localStorage.setItem('tg_expand', true);
                    this.$router.push('/personinfo');
                    window.location.reload();
                  }
                }
              })
              .catch((err) => {
                console.log('err', err);
              });
            this.$message.success('退出成功');

            // this.$emit('getList');
            this.dialogShow = false;
            this.form = {
              deptId: null,
              name: '',
              remark: '',
            };

            // this.$router.push("/login")
          }
        })
        .catch((err) => {
          console.log('err', err);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.tip {
  font-size: 14px;
  font-weight: 500;
  line-height: 40px;
  color: #666666;
}
</style>
